//
//  CGQshebeiCell.swift
//  SheYangBigData
//
//  Created by 叁拾叁 on 2021/4/7.
//  Copyright © 2021 叁拾叁. All rights reserved.
//


import UIKit


class CGQshebeiCell: SYBaseCell {
    
    var bgView: UIView = {
        let v = UIView()
        v.backgroundColor = UIColor.white
        v.layer.cornerRadius = 5.autoWidth()
        v.layer.masksToBounds = true
        return v
    }()
    
    let title: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x333333)
        v.font = 14.autoBoldFontSize()
        v.text = "设备离线"
        return v
    }()
    
    let pic: UIImageView = {
        let v: UIImageView = UIImageView()
        v.sy_name("shebei_lixian")
        return v
    }()
    
    let arrow: UIImageView = {
        let v: UIImageView = UIImageView()
        v.sy_name("arrow_gray")
        return v
    }()
    
    let biaohao: CGQshebeiView = {
        let v = CGQshebeiView()
        v.title.text = "设备编号："
        v.num.text = "设备编号："
        return v
    }()
    
    let leixing: CGQshebeiView = {
        let v = CGQshebeiView()
        v.title.text = "设备类型："
        v.num.text = "设备编号："
        return v
    }()
    
    let xieyi: CGQshebeiView = {
        let v = CGQshebeiView()
        v.title.text = "解析协议"
        v.num.text = "设备编号："
        return v
    }()
    
    let duankou: CGQshebeiTipView = {
        let v = CGQshebeiTipView()
        v.title.text = "采集端口"
        return v
    }()
    
    let mingcheng: CGQshebeiTipView = {
        let v = CGQshebeiTipView()
        v.title.text = "设备名称"
        return v
    }()
    
    
    
    
    @objc func portSelect(btn: UIButton)  {
        
        self.passParamsClosure?("mingcheng")
        
        
    }
    @objc func mingSelect(btn: UIButton)  {
        
        self.passParamsClosure?("duankou")
        
        
    }
    
    public func configureView(model: NSshebeiRecordsModel) {
        //        title.text = model.name
        //        if let p = model.imgPath {
        //            pic.kf.setImage(with: URL(string: IMGIP+p))
        //        }
        
        title.text = model.appName
        biaohao.num.text = model.deviceId
        leixing.num.text = model.protocolDeviceTypeName
        xieyi.num.text = model.protocolName
        duankou.num .setTitle(model.portName, for: .normal)
//        mingcheng.num .setTitle(model.deviceName, for: .normal)
        mingcheng.num.setTitle(String(format: "%@>", model.deviceName ?? ""), for: .normal)

        self.duankou.num.contentEdgeInsets = UIEdgeInsets(top: 6, left: 10, bottom: 6, right: 10);
        

        if model.isOnline == 0{
            
            pic.sy_name("shebei_lixian")
            
        }else if model.isOnline == 1 {
            pic.sy_name("shebei_zaixian")
            
        } else {
            pic.sy_name("shebei_kongxian")
            
        }
        
         
        mingcheng.tip.setTitle(String(format: "启用设备%ld个", model.enabledChildDeviceCount), for: .normal)
        mingcheng.tip.backgroundColor = UIColor(hex:0x0782FF)
        mingcheng.tip.setTitleColor(.white, for: .normal)
        duankou.tip.isHidden = true
    }
    
    override func initViews() {
        
        mingcheng.num.addTarget(self, action: #selector(mingSelect), for: .touchUpInside)
       duankou.num .addTarget(self, action: #selector(portSelect), for: .touchUpInside)
        mingcheng.tip.addTarget(self, action: #selector(mingSelect), for: .touchUpInside)

        self.backgroundColor = .clear
        contentView.addSubview(bgView)
        bgView.addSubview(pic)
        bgView.addSubview(title)
        bgView.addSubview(arrow)
        bgView.addSubview(biaohao)
        bgView.addSubview(leixing)
        bgView.addSubview(xieyi)
        bgView.addSubview(duankou)
        bgView.addSubview(mingcheng)
        bgView.addSubview(lineView)

        bgView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(10.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(10))
            make.right.equalToSuperview().offset(autoWidth(-10))
            make.bottom.equalToSuperview()
        }
        pic.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(17.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(9))
            make.width.equalTo(50.autoWidth())
            make.height.equalTo(24.autoWidth())
            make.bottom.equalToSuperview().offset(-172.autoWidth())
        }
        title.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(22.autoWidth())
            make.left.equalTo(pic.snp.right).offset(autoWidth(10))
            make.right.equalToSuperview().offset(autoWidth(-30))
            make.height.equalTo(15.autoWidth())
        }
        
        arrow.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(22.autoWidth())
            make.right.equalToSuperview().offset(autoWidth(-20.0))
            make.width.equalTo(8.autoWidth())
            make.height.equalTo(14.autoWidth())
        }
        
        biaohao.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(62.autoWidth())
            make.left.equalToSuperview().offset(20.autoWidth())
            make.right.equalToSuperview().offset(-20.autoWidth())
            make.height.equalTo(13.autoWidth())
        }
        
        leixing.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(87.autoWidth())
            make.left.equalToSuperview().offset(20.autoWidth())
            make.right.equalToSuperview().offset(-20.autoWidth())
            make.height.equalTo(13.autoWidth())
        }
        xieyi.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(112.autoWidth())
            make.left.equalToSuperview().offset(20.autoWidth())
            make.right.equalToSuperview().offset(-20.autoWidth())
            make.height.equalTo(13.autoWidth())
        }
        duankou.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(140.autoWidth())
            make.left.equalToSuperview().offset(20.autoWidth())
            make.right.equalToSuperview().offset(-20.autoWidth())
            make.height.equalTo(25.autoWidth())
        }
        mingcheng.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(173.autoWidth())
            make.left.equalToSuperview().offset(20.autoWidth())
            make.right.equalToSuperview().offset(-20.autoWidth())
            make.height.equalTo(25.autoWidth())
        }
        lineView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(autoWidth(10))
            make.right.equalToSuperview().offset(autoWidth(-10.0))
            make.height.equalTo(0.5.autoWidth())
            make.top.equalToSuperview().offset(autoWidth(48))
        }
    }
    
    
}


class CGQshebeiView: SYBaseView {
    
    let title: UILabel = {
        let v = UILabel()
        
        v.font = 14.autoFontSize()
        v.textColor = UIColor(hex: 0x333333)
        return v
    }()
    
    var num: UILabel = {
        let v = UILabel()
        
        v.font = 14.autoFontSize()
        v.textColor = UIColor(hex: 0x666666)
        return v
    }()
    
    
    
    override func initViews() {
        
        addSubview(title)
        addSubview(num)
        
        title.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview()
            make.height.equalTo(13.autoWidth())
        }
        num.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(title.snp.right).offset(14.autoWidth())
            make.height.equalTo(13.autoWidth())
        }
        
    }
}


class CGQshebeiTipView: SYBaseView {
    
    let title: UILabel = {
        let v = UILabel()
        v.text = "设备编号："
        v.font = 14.autoFontSize()
        v.textColor = UIColor(hex: 0x333333)
        return v
    }()
    
    let num: UIButton = {
        //        let v = PaddingLabel(padding: UIEdgeInsets(top: 2, left: 15, bottom: 2, right: 15))
        let v = UIButton()
        
        v.titleLabel?.text = "  无锡惠山主控  "
        v.titleLabel?.font = 13.autoFontSize()
        v.setTitleColor(UIColor(hex: 0x0782FF), for: .normal)
        v.layer.cornerRadius = 12.5.autoWidth()
        v.layer.masksToBounds = true
        v.layer.borderWidth = 0.5
        v.layer.borderColor = UIColor(hex: 0x0782FF).cgColor
        v.contentEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10);
        
        return v
    }()
    
    let tip: UIButton = {
        //        let v = PaddingLabel(padding: UIEdgeInsets(top: 2, left: 15, bottom: 2, right: 15))
        let v = UIButton()
        
        v.titleLabel?.text = "  无锡惠山主控  "
        v.titleLabel?.font = 13.autoFontSize()
        v.setTitleColor(UIColor(hex: 0x0782FF), for: .normal)
        v.layer.cornerRadius = 12.5.autoWidth()
        v.layer.masksToBounds = true
        v.layer.borderWidth = 0.5
        v.layer.borderColor = UIColor(hex: 0x0782FF).cgColor
        v.contentEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10);

        return v
    }()
    
    
    override func initViews() {
        
        addSubview(title)
        addSubview(num)
        addSubview(tip)
        
        title.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview()
            make.height.equalTo(13.autoWidth())
        }
        num.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(77.autoWidth())
            make.height.equalTo(25.autoWidth())
        }
        tip.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(num.snp.right).offset(8.autoWidth())
            make.height.equalTo(25.autoWidth())
        }
    }
}
